package de.elenore.render;

import javax.microedition.khronos.egl.EGLConfig;
import javax.microedition.khronos.opengles.GL10;

import de.elenore.system.SimulationListener;
import de.elenore.util.GameActivity;

import android.opengl.GLSurfaceView.Renderer;

public final class GameRenderer implements Renderer {

    // Simulation als Attribut
    private SimulationListener simulation;
    private GameActivity g;
    private RenderInterface ri;

    public GameRenderer(SimulationListener simulation) {
	setSimulation(simulation);
    }

    public GameRenderer(GameActivity g) {
	this.g = g;
    }

    @Override
    public void onDrawFrame(GL10 gl) {
	if (ri != null)
	    ri.mainLoop(g, gl);

	if (simulation != null)
	    simulation.updateObjects();

    }

    @Override
    public void onSurfaceChanged(GL10 gl, int width, int height) {
	g.setWidth(width);
	g.setHeight(height);
    }

    @Override
    public void onSurfaceCreated(GL10 gl, EGLConfig config) {

	if (ri != null)
	    ri.setup(g, gl);

    }

    public void setSimulation(SimulationListener s) {
	simulation = s;
    }

    public void setRenderInferface(RenderInterface ri) {
	this.ri = ri;
    }

}
